// Copyright (c) 2021 Presto Labs Pte. Ltd.
// Author: xguo

#pragma once

#include <functional>
#include <memory>
#include <string>
#include <unordered_map>

#include "coin2/exchange/base/order/external.h"
#include "coin2/exchange/base/order/processor.h"

namespace coin2::exchange::base::order {

class TradeClient {
 public:
  using OrderConnectionConfig = coin2::exchange::order::OrderConnectionConfig;
  using NativeHttpAsioDriver = base::api_base::NativeHttpAsioDriver;
  using LiveAsyncExecutor = base::api_base::LiveAsyncExecutor;
  using Callback = std::function<void(const RawMessageProto&)>;

  explicit TradeClient(boost::asio::io_context* ioc) : ioc_(ioc) {}
  void SubmitOrderExecution(const OrderExecutionProto& order);
  void SubmitRestQuery(const RestQueryProto& query);
  void AddConfig(const std::string& mea, const OrderConnectionConfig& config);
  void SetCallback(Callback callback);

 private:
  NativePrivateClient* GetNativeClient(const std::string& mea);

 private:
  boost::asio::io_context* ioc_;
  Callback callback_;

  std::unordered_map<std::string, OrderConnectionConfig> config_map_;
  std::unordered_map<std::string, std::unique_ptr<NativePrivateClient>> client_map_;
  std::unordered_map<std::string, std::unique_ptr<NativeHttpAsioDriver>> driver_map_;
};

}  // namespace coin2::exchange::base::order
